import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { TaskVO, TaskForm, TaskQuery } from '@/api/signIn/task/types';

/**
 * 查询任务列表
 * @param query
 * @returns {*}
 */

export const listTask = (query?: TaskQuery): AxiosPromise<TaskVO[]> => {
  return request({
    url: '/signIn/task/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询当前用户所有任务
 */
export const listTaskForUser = (userId: number): AxiosPromise<TaskVO[]> => {
  return request({
    url: 'signIn/task/listForUser',
    method: 'get',
    params: {
      userId: userId
    }
  });
};

/**
 * 查询任务详细
 * @param id
 */
export const getTask = (id: string | number): AxiosPromise<TaskVO> => {
  return request({
    url: '/signIn/task/' + id,
    method: 'get'
  });
};

/**
 * 新增任务
 * @param data
 */
export const addTask = (data: TaskForm) => {
  return request({
    url: '/signIn/task',
    method: 'post',
    data: data
  });
};

/**
 * 修改任务
 * @param data
 */
export const updateTask = (data: TaskForm) => {
  return request({
    url: '/signIn/task',
    method: 'put',
    data: data
  });
};

/**
 * 删除任务
 * @param id
 */
export const delTask = (id: string | number | Array<string | number>) => {
  return request({
    url: '/signIn/task/' + id,
    method: 'delete'
  });
};
